package com.cet.lxf.oop.test04;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * @program: algorithm
 * @description: Java的String和char在内存中总是以Unicode编码表示
 * @author: 陈恩涛
 * @create: 2021-06-25 15:56
 **/
public class Main03 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        byte[] b1 = "Hello".getBytes(); // 按系统默认编码转换，不推荐
        byte[] b2 = "Hello".getBytes("UTF-8"); // 按UTF-8编码转换
        byte[] b3 = "Hello".getBytes("GBK"); // 按GBK编码转换
        byte[] b4 = "Hello".getBytes(StandardCharsets.UTF_8); // 按UTF-8编码转换

        System.out.println(Arrays.toString(b1));
        System.out.println(Arrays.toString(b2));
        System.out.println(Arrays.toString(b3));
        System.out.println(Arrays.toString(b4));
    }
}
